package cn.woflcode.game.model;

import cn.woflcode.game.Global.Global;
import cn.woflcode.game.Global.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
/**
 * 英雄战机的子弹
 */
public class HeroBullet {
    //---------------------状态-------------------------------------------------
    //位置:x坐标
    private int x;
    //位置:y坐标
    private int y;
    //大小:宽
    private int width;
    //大小:高
    private int height;
    //子弹的图片
    private BufferedImage image = ImageUtil.getImage("hero_bullet0");
    private BufferedImage image2 = ImageUtil.getImage("az");
    private BufferedImage image3 = ImageUtil.getImage("dd");
    //飞行速度
    private int speed=25;
    //状态
    private Global.FlyObjectState state = Global.FlyObjectState.ALIVE;
    //----------------------构造器----------------------------------------------
    public HeroBullet(int x,int y){
        this.width=image.getWidth();
        this.height=image.getHeight();
        this.x=x -width/2 -5;
        this.y=y-height/2-12;
    }
    //----------------------功能------------------------------------------------
    //绘制子弹
    public void drawSelf(Graphics g){
        if (HeroPlane.totalScore >= 20){
            g.drawImage(image3,x,y,null);
        }
        if (HeroPlane.totalScore >= 30){
            g.drawImage(image2,x,y,null);
        }
        g.drawImage(image,x,y,null);
    }
    //移动方法
    public void move(){
        this.y -= speed;
    }
    //获取英雄战机子弹外围的圆形的圆心（x,y）和半径
    //圆 x坐标
    public int getCenterX(){
        return x+width/2;
    }
    //圆y坐标
    public int getCenterY(){
        return y+Math.min(width,height)/2;
    }
    //圆半径
    public int getR(){
        return Math.min(width,height)/2;
    }
    //判断是否越界
    public boolean outOfBound(){
        return this.y <= -this.height;
        //此时,如果是true,说明子弹已经离开了游戏界面,应当清理
    }
    public Global.FlyObjectState getState(){
        return state;
    }
    public void setState(Global.FlyObjectState state) {
        this.state = state;
    }
}
